//
//  DateTimeRecord.m
//  SimulacraDB
//
//  Created by Andre Cohen on 8/31/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "DateTimeRecord.h"


@implementation DateTimeRecord

@synthesize value;

- (id)initWithData:(ByteArray *)data {
	[super init];
	[self setValueFromData:data];
	return self;
}

- (id)initWithValue:(NSObject *)data {
	[super init];
	[self setValue:data];
	return self;
}

- (void)setValueFromData:(ByteArray *)data {
	value = [[[DateTime alloc] init] autorelease];

	if([data count]<18)
		return;
	
	[value setDateFromStamp:[data getFloatFromLocation:0]];
	[value setTimeFromStamp:[data getFloatFromLocation:8]];
	[value setZone:[data getIntFromLocation:16]];
}

- (ByteArray *)toByteArray {
	ByteArray *data = [[[ByteArray alloc] init] autorelease];
	[data appendFloat:[value dateStamp]];
	[data appendFloat:[value timeStamp]];
	[data appendInt:[value zone]];
	return data;
}

- (void)setValue:(NSObject *)object {
	value = [DateTime createFromString:(NSString *)object];
}

- (int)size {
	return 18;
}

- (NSString *)description {
	return [value description];
}

- (BOOL)lessThan:(id)anObject {
	return [value compare:[anObject value]]==NSOrderedAscending;
}
- (BOOL)greaterThan:(id)anObject {
	return [value compare:[anObject value]]==NSOrderedDescending;
}
- (BOOL)equalTo:(id)anObject {
	return [value compare:[anObject value]]==NSOrderedSame;
}



@end
